﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
    <script src="lib/jquery/dist/jquery.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            console.log("Jquery Ready");
            //$.ajax({
            //    type: "post",
            //    contentType: 'application/json; charset=utf-8',
            //    url: "http://localhost:58198/api/WechatJSSDK",
            //    data: { url: "string" },
            //    dataType: "json",
            //    success: function (data) {
            //        console.log(data)
            //    }, error: function (e) {
            //        console.log(e);
            //    }
            //});
            $.ajax({
                url: "http://localhost:58198/api/WechatJSSDK",
                type: "POST",
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify({ 'url': location.href }),
                dataType: "json",
                success: function (result) {
                    console.log(result);
                    if (result.code == 0) {
                        wx.config({
                            debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                            appId: result.data.appId, // 必填，公众号的唯一标识
                            timestamp: result.data.timestamp, // 必填，生成签名的时间戳
                            nonceStr: result.data.nonceStr, // 必填，生成签名的随机串
                            signature: result.data.signature,// 必填，签名
                            jsApiList: [
                                'checkJsApi',
                                'onMenuShareTimeline',
                                'onMenuShareAppMessage',
                                'onMenuShareQQ',
                                'onMenuShareWeibo',
                                'hideMenuItems',
                                'showMenuItems',
                                'hideAllNonBaseMenuItem',
                                'showAllNonBaseMenuItem',
                                'translateVoice',
                                'startRecord',
                                'stopRecord',
                                'onRecordEnd',
                                'playVoice',
                                'pauseVoice',
                                'stopVoice',
                                'uploadVoice',
                                'downloadVoice',
                                'chooseImage',
                                'previewImage',
                                'uploadImage',
                                'downloadImage',
                                'getNetworkType',
                                'openLocation',
                                'getLocation',
                                'hideOptionMenu',
                                'showOptionMenu',
                                'closeWindow',
                                'scanQRCode',
                                'chooseWXPay',
                                'openProductSpecificView',
                                'addCard',
                                'chooseCard',
                                'openCard'
                            ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2。详见：http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
                        });
                    } else {
                        console.log('请求失败！');
                    }
                },
                error: function (msg) {
                    console.log(msg);
                }
            })
        });
        wx.error(function (res) {
            console.log(res);
            alert('验证失败');
        });

        wx.ready(function () {
            var url = '@(Context.Request.Scheme)://sdk.weixin.senparc.com';
            var link = url + '@(Context.Request.PathAndQuery())';
            var imgUrl = url + '/images/v2/ewm_01.png';

            //转发到朋友圈
            wx.onMenuShareTimeline({
                title: 'JSSDK朋友圈转发测试',
                link: link,
                imgUrl: imgUrl,
                success: function () {
                    alert('转发成功！');
                },
                cancel: function () {
                    alert('转发失败！');
                }
            });
            //转发给朋友
            wx.onMenuShareAppMessage({
                title: 'JSSDK朋友圈转发测试',
                desc: '转发给朋友',
                link: link,
                imgUrl: imgUrl,
                type: 'link',
                dataUrl: '',
                success: function () {
                    alert('转发成功！');
                },
                cancel: function () {
                    alert('转发失败！');
                }
            });
        });
    </script>
</head>
<body>

</body>
</html>